import axios from 'axios'
const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API,
    timeout: 36000 // request timeout
})

// request interceptor
service.interceptors.request.use(

    config => {

        return config
    },
    error => {
        // do something with request error
        console.log(error) // for debug
        return Promise.reject(error)
    }
)

// response interceptor
service.interceptors.response.use(

    response => {
        const res = response.data

        if (res.code !== 200) {
            // if (res.code == 401) {
            //     removeToken()
            //     sessionStorage.removeItem("user")
            //     store.state.userInfo = null
            //     store.state.loginFlag = true
            // }

            return Promise.reject(new Error(res.message || 'Error'))
        } else {
            return res
        }
    },
    error => {
        return Promise.reject(error)
    }
)

export default service